//
//  Object.cpp
//  Simulation
//
//  Created by Christopher Kemsley on 2/27/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#include "Object.hpp"
#include "Exception.hpp"
#include "AutoreleasePool.hpp"


using namespace Sim ;




Object :: Object ()
:	mRetainCount(1)
	{
	
	}

Object :: ~Object ()
	{
	
	}


void	Object :: retain ()
	{
	if ( mRetainCount == 0 )
		throw Exception ( "Object" , "Object retained, but retain count is zero" , __FILE__,__LINE__ ) ;
	mRetainCount ++ ;
	}

void	Object :: release ()
	{
	if ( mRetainCount == 0 )
		throw Exception ( "Object" , "Object released, but retain count is zero" , __FILE__,__LINE__ ) ;
	else if ( mRetainCount == 1 )
		delete this ;
	else
		mRetainCount -- ;
	}
void	Object :: autorelease ()
	{
	AutoreleasePool::current() . autorelease ( this ) ;
	}
